//
//  NewFeatureViewController.m
//  WeiBTest
//
//  Created by Zc_zhou on 15/9/10.
//  Copyright (c) 2015年 Apple. All rights reserved.
//
#import "MainViewController.h"
#import "NewFeatureViewController.h"
#define ImageNumber 4

@interface NewFeatureViewController ()<UIScrollViewDelegate>
@property (nonatomic, strong)UIScrollView *scrollView;
@property (nonatomic, strong)UIPageControl *pageControl;
@end

@implementation NewFeatureViewController

-(UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
    }
    return _scrollView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.scrollView.frame = self.view.bounds;
    self.scrollView.delegate = self;
    self.scrollView.userInteractionEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(ImageNumber*self.view.width, 0);
    self.scrollView.pagingEnabled = YES;
    [self.view addSubview:self.scrollView];
    for (int i = 0; i<ImageNumber; i++) {
        UIImageView *image = [[UIImageView alloc] init];
        NSString *name = [NSString stringWithFormat:@"new_feature_%d", i + 1];
        image.image = [UIImage imageNamed:name];
        image.frame = CGRectMake(self.scrollView.width*i, 0, self.scrollView.width, self.scrollView.height);
        image.userInteractionEnabled = YES;
        [self.scrollView addSubview:image];
        if  (i == ImageNumber-1)
        {
            [self setupLastImageView:image];
        }
    }
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.numberOfPages = ImageNumber;
    [self.view addSubview:pageControl];
    pageControl.width = 200;
    pageControl.height = 30;
    pageControl.centerX = self.scrollView.width*0.5;
    pageControl.y = self.view.height-50;
    pageControl.currentPageIndicatorTintColor = HWcolor(253, 98, 42);
    pageControl.pageIndicatorTintColor = HWcolor(189, 189, 189);
    self.pageControl = pageControl;
}
- (void)setupLastImageView:(UIImageView *)image
{
    UIButton *btn = [[UIButton alloc] init];
    btn.width = 150;
    btn.height = 30;
    btn.centerX =  image.width * 0.5;;
    btn.y = self.view.height*0.65;

    [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
    [btn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    [btn setTitle:@"分享给大家" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [image addSubview:btn];
    
    
    UIButton *starBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [starBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [starBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    starBtn.size = starBtn.currentBackgroundImage.size;
    starBtn.centerX = image.width*0.5;
    starBtn.y = image.height*0.75;
    [starBtn setTitle:@"开始微博" forState:UIControlStateNormal];
    [starBtn addTarget:self action:@selector(starClick:) forControlEvents:UIControlEventTouchUpInside];
    [image addSubview:starBtn];
}
- (void)btnclick:(UIButton*)btn
{
    btn.selected = !btn.selected;
}
- (void)starClick:(UIButton *)btn
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.rootViewController = [[MainViewController alloc] init];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat pageNum = self.scrollView.contentOffset.x/self.view.width;
    self.pageControl.currentPage = (int)(pageNum+0.5);
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
